package com.song.test;

import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @Author Klys
 * @Date 2023/6/7 16:57
 * @Description
 * @Version 1.0
 */
@Slf4j
public class Demo {


    public static void main(String[] args) {


        Map<String, Integer> myMap = new HashMap<>();
        myMap.put("key1", 10);
        myMap.put("key2", 20);
        myMap.put("key3", 30);

        myMap = myMap.entrySet().stream()
                .map(entry -> {
                    if (entry.getKey().equals("key2")) {
                        entry.setValue(50);
                    }
                    return entry;
                })
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

        System.out.println(myMap);


        Map<String, String> map = new HashMap<>();
        map.put("key1", "10");
        map.put("key2", "20");
        map.put("key3", "30");
        map = map.entrySet().stream()
                .map(entry -> {
                    String s = entry.getValue().toString();
                    Object o = entry.setValue(s + "字头");
                    return entry;
                })
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
        System.out.println(map);

        HashSet<Object> hashSet = new HashSet<>();
        hashSet.add("1");
        hashSet.add("2");
        Set<String> collect = hashSet.stream().map(a -> a + "klys").collect(Collectors.toSet());
        System.out.println(collect);

        for (Object str : hashSet
        ) {
            System.out.println(str);
        }
    }
}
